package com.llxy.web.controller.worker;
import com.llxy.common.annotation.Log;
import com.llxy.common.core.controller.BaseController;
import com.llxy.common.core.domain.AjaxResult;
import com.llxy.common.core.page.TableDataInfo;
import com.llxy.common.enums.BusinessType;
import com.llxy.worker.domain.Train;
import com.llxy.worker.dto.TrainDTO;
import com.llxy.worker.service.TrainService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
* (t_train)表控制层
*
* @author 马瑞龙
*/
@RestController
@RequestMapping("/worker/train")
public class TrainController extends BaseController {
    /**
    * 服务对象
    */
    @Autowired
    private TrainService trainService;

    /**
     * 获取培训列表
     */
    @PreAuthorize("@ss.hasPermi('worker:train:list')")
    @GetMapping("/list")
    public TableDataInfo list(Train train)
    {
        startPage();
        List<TrainDTO> trainDTOList = trainService.selectTrainList(getUserId(),train);
        return getDataTable(trainDTOList);
    }

    /**
     * 新增培训
     */
    @PreAuthorize("@ss.hasPermi('worker:train:add')")
    @Log(title = "培训管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody Train train)
    {
        return toAjax(trainService.insertSelective(train));
    }

    /**
     * 修改培训
     */
    @PreAuthorize("@ss.hasPermi('worker:train:edit')")
    @Log(title = "培训管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody Train train)
    {
        return toAjax(trainService.updateByPrimaryKeySelective(train));
    }

    /**
     * 根据培训编号获取详细信息
     */
    @PreAuthorize("@ss.hasPermi('worker:train:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable Integer id)
    {
        return success(trainService.selectByPrimaryKey(id));
    }

    /**
     * 删除培训
     */
    @PreAuthorize("@ss.hasPermi('worker:train:remove')")
    @Log(title = "培训管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Integer id)
    {
        return toAjax(trainService.deleteByPrimaryKey(id));
    }

}
